package common

import (
	"Project/global"
	"Project/model/area/response"
	"fmt"
	execel "github.com/xuri/excelize/v2"
)
type ExcelService struct {}

func (e *ExcelService) RecordExcel(data []response.DrugRecordList,filePath string)(err error){
	// 创建excel文件
	exc := execel.NewFile()
	// 创建头部
	exc.SetSheetRow("Sheet1","A1",&global.TableName)
	for i,v := range data{
		axis := fmt.Sprintf("A%d",i+2)
		exc.SetSheetRow("Sheet1",axis,&[]interface{}{
			v.UserName,
			v.Card,
			v.Phone,
			v.HighRisk,
			v.DrugList,
			v.LivingArea,
			v.Address,
			v.ReasonUse,
			v.SaleName,
			v.Time,
		})
	}
	err = exc.SaveAs(filePath)
	return err
}
